package com.itheima.hmshopping.dubbo.apiImpl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.hmshopping.dubbo.api.SmsCouponHistoryServiceApi;
import com.itheima.hmshopping.dubbo.mapper.SmsCouponHistoryMapper;
import com.itheima.hmshopping.entity.SmsCouponHistory;
import com.mysql.jdbc.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class SmsCouponHistoryServiceApiImpi implements SmsCouponHistoryServiceApi {

    @Autowired
    private SmsCouponHistoryMapper smsCouponHistoryMapper;

    //根据优惠券id，使用状态，订单编号分页获取领取记录
    @Override
    public Page<SmsCouponHistory> page(Integer couponId, String orderSn, Integer pageNum, Integer pageSize, Integer useStatus) {
        Page<SmsCouponHistory> page=new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<SmsCouponHistory> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        if (ObjectUtil.isNotEmpty(couponId)){
            lambdaQueryWrapper.eq(SmsCouponHistory::getCouponId,couponId);
        }
        if (StrUtil.isNotBlank(orderSn)){
            lambdaQueryWrapper.eq(SmsCouponHistory::getOrderSn,orderSn);
        }
        if (ObjectUtil.isNotEmpty(useStatus)){
            lambdaQueryWrapper.eq(SmsCouponHistory::getUseStatus,useStatus);
        }
        Page<SmsCouponHistory> selectPage = smsCouponHistoryMapper.selectPage(page, lambdaQueryWrapper);
        return selectPage;
    }
}
